import javax.jms.*;
import javax.jms.Message;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class analyseListen implements MessageListener {
    private ArrayList<Double> minNums = new ArrayList<>();
    private ArrayList<Double> maxNums = new ArrayList<>();
    private ArrayList<Double> means = new ArrayList<>();
    private ArrayList<Double> variances = new ArrayList<>();
    int i=0;
    String[] legends=new String[4];
    public void onMessage(Message message) {
        try {
            StreamMessage m=(StreamMessage)message;
            double minNum=m.readDouble();
            double maxNum=m.readDouble();
            double mean=m.readDouble();
            double variance=m.readDouble();
            System.out.println("收到的随机信号分析部分: "+minNum+"  "+maxNum+"  "+mean+"  "+variance);
            minNums.add(minNum);maxNums.add(maxNum);
            means.add(mean);variances.add(variance);
            i=i+1;
            if(i%10==0)
            {
                ArrayList<ArrayList<Double>> data = new ArrayList<>();
                data.add(minNums);
                data.add(maxNums);
                data.add(means);
                data.add(variances);
                legends[0]="min";
                legends[1]="max";
                legends[2]="means per 100";
                legends[3]="variance per 100";
                LineChart chart = new LineChart("analyse result", "analyse result",data,legends);
                chart.pack();
                chart.setVisible(true);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
